import { Component } from '@angular/core';
import { Router} from '@angular/router';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  constructor(private router: Router) { }
  title = 'angular';
  goToPage(url){
    this.router.navigateByUrl(url);
    // history.pushState(null, null, url);
    if(url.startsWith('/app-react')){
      // react hash 模式直接跳转路由不会响应，需要触发一下 hash 事件
      const event = new Event('hashchange');
      window.dispatchEvent(event);
    }
  }
}
